<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    /* 数据代理 */
    let Person = {}
    Person.name = 'Jack'
    Person['gender'] = 'female'
    console.log(Person.name);
    console.log(Person.gender);

    let tmpAge = null
    Object.defineProperty(Person, 'age', {
        /* value : 20,
        // 默认为false即不可修改
        writable: true, */
        /* 使用getter和setter后不允许再使用 writable 和value配置*/
        // false不可删除属性 delete Person.age返回false
        configrable: false,
        // 默认false  不可被枚举
        enumerable: true,
        get(){
            console.log("读取age值")
            return tmpAge
        },
        set(val){
            console.log("设置age值");
            tmpAge = val
        }
    })

    Person.age = 21
    console.log(Person.age); // writable为false  此处为undefined
    // 枚举
    console.log(Object.keys(Person));
    for(let key in Person) {console.log(key);}
    console.log(Person.propertyIsEnumerable('age'));
</script>
</html>